//
//  YSGHelpCenterQuestion.swift
//  EyeVisionForPatients
//
//  Created by PMC on 2020/11/19.
//  Copyright © 2020 QDSG. All rights reserved.
//

import HandyJSON

struct YSGHelpCenterQuestion: HandyJSON {
    var id: Int = 0
    var title: String?
    var isDelete: Int = 0
    var content: String?
    var createTime: Date?
    var updateTime: Date?
    var type: String?
    var `operator`: Int = 0
}

struct YSGHelpCenterQuestionViewModel {
    let models: [YSGHelpCenterQuestion]
    
    var numberOfSection: Int { models.count }
    
    func viewModel(at indexPath: IndexPath) -> YSGHelpCenterQuestionCellViewModel {
        return YSGHelpCenterQuestionCellViewModel(model: models[indexPath.section])
    }
    
    /// 获取问题列表
    /// type: 问题类型
    /// tital: 问题标题模糊搜索用
    static func getQuestionList(type: String, tital: String, finished: @escaping ([YSGHelpCenterQuestion], String?, HttpCode) -> Void) {
        let params: [String: Any] = [
            "type": type,
            "tital": tital,
            "current": 1,
            "size": 100
        ]
        HttpTool.shared.request(target: ApiManager.helpCenterQuestionList(paras: params), success: { (json, code) in
            YSGLog(json)
            if let models = JSONDeserializer<YSGHelpCenterQuestion>.deserializeModelArrayFrom(json: json["data"]["records"].description) as? [YSGHelpCenterQuestion] {
                finished(models, json["message"].description, code)
            } else {
                finished([], "数据解析错误，请重试", .failure)
            }
        }) { error in
            finished([], error, .failure)
        }
    }
}

struct YSGHelpCenterQuestionCellViewModel {
    let model: YSGHelpCenterQuestion
}
